package it.afs.worklog.application;

import it.afs.worklog.application.form.InsertLogPage;
import it.afs.worklog.application.form.ReportPage;
import it.afs.worklog.application.form.admin.ClientiPage;
import it.afs.worklog.application.form.admin.CommessePage;
import it.afs.worklog.application.form.admin.UtentiPage;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.Link;

/**
 * @author Fanta
 */
public class HomePage extends LoggedPage
{

	public HomePage()
	{
		super();
		
		addComponents();
	}
	
	@Override
	protected void addComponents()
	{
		super.addComponents();
		
		add(new Link<Void>("insert-log")
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(InsertLogPage.class);
			}
		});
		
		add(new Link<Void>("report")
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(ReportPage.class);
			}
		});
		
		WebMarkupContainer adminPanel = new WebMarkupContainer("admin-panel")
		{
			private static final long serialVersionUID = 1L;

			@Override
			protected void onConfigure()
			{
				super.onConfigure();
				setVisible(WorkLogSession.getCurrentSession().getLoggedUser().isAdmin());
			}
		};
		add(adminPanel);
		
		adminPanel.add(new WebMarkupContainer("admin-link")
		{
			private static final long serialVersionUID = 1L;

			@Override
			protected void onComponentTag(ComponentTag tag)
			{
				super.onComponentTag(tag);
				tag.put("onclick", "$(\"#admin-tools\").toggle(500)");
			}
			
		});
		
		adminPanel.add(new Link<Void>("admin-clienti-link")
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(ClientiPage.class);
			}
		});
		
		adminPanel.add(new Link<Void>("admin-commesse-link")
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(CommessePage.class);
			}
		});
		
		adminPanel.add(new Link<Void>("admin-utenti-link")
		{
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(UtentiPage.class);
			}
		});
	}
}